import matplotlib.pyplot as plt
import numpy as np

from rootPath import project_path

species = ("MR", "MR+RD+EE", "MR+WR+EE", "MR+RD+ET", "MR+WR+ET")
penguin_means = {
    'Client1': (17.47, 17.97, 17.46, 12.89, 14.00),
    'Client2': (17.22, 17.14, 17.39, 13.80, 14.22),
    'Client3': (20.61, 20.42, 20.77, 19.97, 20.20),
    'Client4': (20.48, 20.07, 20.36, 20.53, 19.59),
    'Client5': (24.22, 24.40, 24.02, 32.80, 31.99),
}

x = np.arange(len(species))  # the label locations
width = 0.10  # the width of the bars
multiplier = 0

fig, ax = plt.subplots(figsize=(12, 6), layout='constrained')

for attribute, measurement in penguin_means.items():
    offset = width * multiplier
    rects = ax.bar(x + offset, measurement, width, label=attribute)
    # ax.bar_label(rects, padding=3, fontsize=6)  # 设置字体大小为12
    multiplier += 1


size = 20
ax.set_ylabel('contribution percentage', fontsize=size)
# ax.set_xticks(x + width, species,fontsize=15)
ax.tick_params(axis='y', labelsize=size)
ax.set_xticks(x + width * (len(penguin_means) - 1) / 2, species, fontsize=size)
ax.legend(loc='upper left', ncols=3, fontsize=size)
ax.set_ylim(0, 35)

# 保存图形到文件，确保文件名包含 .png 扩展名
plt.savefig(project_path + '/experiment/imgs/contributions_sdds.png', dpi=300, bbox_inches='tight')
plt.show()
